package com.bdqn.spark.chapter05.seirialize

import org.apache.spark.{SparkConf, SparkContext}

object Spark07_RDD_Operator_Action {
  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("Operator")
    val sc = new SparkContext(sparkConf)

    val rdd = sc.makeRDD(List[Int](1,2,3,4),1)

    val user = new Person()

    // SparkException: Task not serializable
    // NotSerializableException: com.bdqn.spark.core.chapter05.rdd.action.Spark07_RDD_Operator_Action$Person

    // RDD算子中传递的函数是会包含闭包操作，那么就会进行检测功能
    // 闭包检测
    rdd.foreach(
      num => {
        println("age = " + (user.age + num))
      }
    )

    sc.stop()
  }

  // 普通的类型：没有序列化
//  class Person extends Serializable {
  // scala中样例类，会自动混入Serializable
  case class Person() {
    var age : Int = 30
  }
}
